package ru.ipccenter.jshell.frontend.beans;

import javax.ejb.Local;
import javax.ejb.Stateful;

import ru.ipccenter.jshell.frontend.compiler.Compiler;
import ru.ipccenter.jshell.frontend.shell.ShellInternal;



import java.io.File;

@Stateful
@Local(User.class)
public class UserBean implements User {
    private String jsessionId;
    private Compiler compiler;
    private ShellInternal shell;
    private String userDir;

    public UserBean() {

    }

    public String getJsessionId(){
        return this.jsessionId;
    }

    public void setJsettionId(String jsessionid){
        this.jsessionId = jsessionid;

        File allUsersDir = new File("./user_data");
        if (!allUsersDir.exists()) {
            allUsersDir.mkdir();
        }

        File userDir = new File(allUsersDir, jsessionId);
        if (!userDir.exists()) {
            userDir.mkdir();
        }

        setUserDir(userDir.getAbsolutePath());
    }

    public String getUserDir(){
        return this.userDir;
    }

    protected void setUserDir(String userDir){
        this.userDir=userDir;
    }

    public Compiler getCompiler(){
        return this.compiler;
    }

    public void setCompiler(Compiler compiler){
        this.compiler=compiler;
    }

    public ShellInternal getShell(){
        return this.shell;
    }

    public void setShell(ShellInternal shell){
        this.shell=shell;
    }

}